package com.appwoo.txtws.activity;

import android.app.ProgressDialog;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RatingBar;
import android.widget.TextView;
import com.appwoo.txtws.adapter.ListViewCreator;
import com.appwoo.txtws.adapter.Page;
import com.appwoo.txtws.adapter.SimpleListAdapter;
import com.appwoo.txtws.app.App;
import com.appwoo.txtws.app.AppActivity;
import com.appwoo.txtws.bean.AutoSoftInfo;
import com.appwoo.txtws.bean.StateBean;
import com.appwoo.txtws.component.DBHelper;
import com.appwoo.txtws.component.Global;
import com.appwoo.txtws.component.Logger;
import com.appwoo.txtws.component.RqSP;
import com.appwoo.txtws.service.RecomSoftServer;
import com.appwoo.txtws.wheel.widget.PageListView;
import com.appwoo.txtws.wheel.widget.PageListView.OnRefreshListener;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AllAppForChildActivity extends AppActivity
{
  public static Map<String, AsyncTask> downAT;
  public static List<AutoSoftInfo> eventsDown;
  public static Boolean isCancel;
  public static Boolean paused;
  private SimpleListAdapter<AutoSoftInfo> adapter;
  private String apkname = "";
  private String apkpath = "";
  private StateBean bean = new StateBean();
  private boolean blDataTask = false;
  private Button btnCurrent;
  private DBHelper dbhelper;
  private ProgressDialog dialog = null;
  private EditText etSearch;
  private List<AutoSoftInfo> events;
  private Boolean isFoot = Boolean.valueOf(false);
  private int isHot = 1;
  private Boolean isSDCard = Boolean.valueOf(false);
  private ImageView ivSearch;
  private PageListView lvList;
  private Page<AutoSoftInfo> page = new Page();
  private String softid = "";

  private Boolean getIsCancelDown(String paramString)
  {
    Boolean localBoolean = Boolean.valueOf(true);
    for (int i = 0; ; i++)
    {
      if (i >= eventsDown.size())
        return localBoolean;
      if (paramString.equals(((AutoSoftInfo)eventsDown.get(i)).getKeyID()))
        return ((AutoSoftInfo)eventsDown.get(i)).getIsCancelDownload();
    }
  }

  private void initView()
  {
    this.isSDCard = Boolean.valueOf(Global.isSDCard());
    this.dbhelper = new DBHelper(this);
    if (eventsDown == null)
      eventsDown = new ArrayList();
    if (downAT == null)
      downAT = new HashMap();
    this.lvList = ((PageListView)findViewById(2131492985));
    this.etSearch = ((EditText)findViewById(2131493268));
    this.ivSearch = ((ImageView)findViewById(2131493269));
    this.ivSearch.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        ((InputMethodManager)AllAppForChildActivity.this.getSystemService("input_method")).hideSoftInputFromWindow(AllAppForChildActivity.this.getCurrentFocus().getWindowToken(), 2);
        AllAppForChildActivity.this.page.removeAll();
        AllAppForChildActivity.this.isFoot = Boolean.valueOf(false);
        AllAppForChildActivity.this.page.firstPage();
        AllAppForChildActivity.this.lvList.showFooterMoreView();
        AllAppForChildActivity.this.lvList.setIsNoMore(false);
        new AllAppForChildActivity.DataTask(AllAppForChildActivity.this).execute(new String[] { "installindex" });
      }
    });
    this.adapter = new SimpleListAdapter(this.page.getEntries(), new ListViewCreator()
    {
      public View createView(final AutoSoftInfo paramAnonymousAutoSoftInfo, View paramAnonymousView, int paramAnonymousInt)
      {
        if (paramAnonymousView == null)
          paramAnonymousView = App.getLayoutInflater().inflate(2130903122, null);
        ((TextView)paramAnonymousView.findViewById(2131493160)).setText(paramAnonymousAutoSoftInfo.getSoftSize());
        ((TextView)paramAnonymousView.findViewById(2131493155)).setText(paramAnonymousAutoSoftInfo.getAsname());
        ((TextView)paramAnonymousView.findViewById(2131493158)).setText(paramAnonymousAutoSoftInfo.getDesc());
        ImageView localImageView = (ImageView)paramAnonymousView.findViewById(2131493154);
        Button localButton;
        int i;
        int j;
        int k;
        int m;
        if (paramAnonymousAutoSoftInfo.getIsRecd() == 1)
        {
          ((ImageView)paramAnonymousView.findViewById(2131493159)).setVisibility(0);
          AllAppForChildActivity.this.loadLogoImage(localImageView, paramAnonymousAutoSoftInfo.getAdicon(), AllAppForChildActivity.this.isSDCard);
          RatingBar localRatingBar = (RatingBar)paramAnonymousView.findViewById(2131493157);
          localRatingBar.setVisibility(0);
          localRatingBar.setRating(Float.parseFloat(paramAnonymousAutoSoftInfo.getHotMark()));
          localButton = (Button)paramAnonymousView.findViewById(2131493156);
          i = localButton.getPaddingLeft();
          j = localButton.getPaddingTop();
          k = localButton.getPaddingRight();
          m = localButton.getPaddingBottom();
          if (!Global.checkApkExist(AllAppForChildActivity.this, paramAnonymousAutoSoftInfo.getAspkg()))
            break label340;
          localButton.setText(AllAppForChildActivity.this.getResources().getString(2131427501));
          localButton.setTextColor(AllAppForChildActivity.this.getResources().getColor(2131230724));
          localButton.setBackgroundDrawable(AllAppForChildActivity.this.getResources().getDrawable(2130837636));
          localButton.setEnabled(false);
        }
        while (true)
        {
          localButton.setPadding(i, j, k, m);
          final ProgressBar localProgressBar = (ProgressBar)paramAnonymousView.findViewById(2131493072);
          AllAppForChildActivity.this.setCurrentProgressBar(paramAnonymousAutoSoftInfo.getKeyID(), localProgressBar, localButton);
          localButton.setOnClickListener(new View.OnClickListener()
          {
            public void onClick(View paramAnonymous2View)
            {
              Button localButton = (Button)paramAnonymous2View;
              if ((!Global.isSDCard()) && (Global.getMemorySize() < 10 + 5 * (1 + AllAppForChildActivity.eventsDown.size())))
              {
                AllAppForChildActivity.this.alertMessage("手机空间不足，不能完成安装。");
                return;
              }
              if ((AllAppForChildActivity.eventsDown.size() >= 3) && ((localButton.getTag() == null) || ("".equals(localButton.getTag()))))
              {
                AllAppForChildActivity.this.alertMessage(AllAppForChildActivity.this.getString(2131428059));
                return;
              }
              if ("安装".equals(localButton.getText()))
              {
                AllAppForChildActivity.this.apkpath = paramAnonymousAutoSoftInfo.getAddownloadurl();
                AllAppForChildActivity.this.apkname = paramAnonymousAutoSoftInfo.getAspkg();
                localButton.setTag(paramAnonymousAutoSoftInfo.getKeyID());
                paramAnonymousAutoSoftInfo.setIsCancelDownload(Boolean.valueOf(false));
                AllAppForChildActivity.eventsDown.add(paramAnonymousAutoSoftInfo);
                localButton.setText("取消");
                AllAppForChildActivity.this.dbhelper.insertSoftsMarket(AllAppForChildActivity.this.apkname);
                localProgressBar.setVisibility(0);
                AllAppForChildActivity.this.showView(localProgressBar, (Button)paramAnonymous2View);
                return;
              }
              AllAppForChildActivity.this.setEventIsCancelDown(Boolean.valueOf(true), paramAnonymousAutoSoftInfo.getKeyID());
              localButton.setText("安装");
              localButton.setTag(null);
              localProgressBar.setProgress(0);
              localProgressBar.setVisibility(8);
            }
          });
          paramAnonymousView.setOnClickListener(new View.OnClickListener()
          {
            public void onClick(View paramAnonymous2View)
            {
              Bundle localBundle = new Bundle();
              localBundle.putString("softName", paramAnonymousAutoSoftInfo.getAsname());
              localBundle.putString("apkname", paramAnonymousAutoSoftInfo.getAspkg());
              localBundle.putString("author", paramAnonymousAutoSoftInfo.getAuthor());
              localBundle.putString("hotMark", paramAnonymousAutoSoftInfo.getHotMark());
              localBundle.putString("softSize", paramAnonymousAutoSoftInfo.getSoftSize());
              localBundle.putString("softType", paramAnonymousAutoSoftInfo.getTypeName());
              localBundle.putString("updateTime", paramAnonymousAutoSoftInfo.getUpdateTime());
              localBundle.putString("downloadurl", paramAnonymousAutoSoftInfo.getAddownloadurl());
              localBundle.putString("icon", paramAnonymousAutoSoftInfo.getAdicon());
              localBundle.putString("keyid", paramAnonymousAutoSoftInfo.getKeyID());
              localBundle.putString("version", paramAnonymousAutoSoftInfo.getVersion());
              AllAppForChildActivity.this.IntentActivity(AllAppForChildActivity.this, SoftInfoActivity.class, localBundle);
            }
          });
          return paramAnonymousView;
          ((ImageView)paramAnonymousView.findViewById(2131493159)).setVisibility(8);
          break;
          label340: localButton.setText(AllAppForChildActivity.this.getResources().getString(2131427500));
          localButton.setTextColor(AllAppForChildActivity.this.getResources().getColor(2131230728));
          localButton.setBackgroundDrawable(AllAppForChildActivity.this.getResources().getDrawable(2130837632));
          localButton.setEnabled(true);
        }
      }
    });
    this.lvList.setAdapter(this.adapter);
    this.lvList.setOnScrollListener(new AbsListView.OnScrollListener()
    {
      public void onScroll(AbsListView paramAnonymousAbsListView, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3)
      {
      }

      public void onScrollStateChanged(AbsListView paramAnonymousAbsListView, int paramAnonymousInt)
      {
        if ((paramAnonymousInt == 0) && (paramAnonymousAbsListView.getLastVisiblePosition() == -1 + paramAnonymousAbsListView.getCount()) && (!AllAppForChildActivity.this.lvList.getIsNoMore()) && (AllAppForChildActivity.this.blDataTask))
        {
          AllAppForChildActivity.this.lvList.prepareForRefreshMore();
          AllAppForChildActivity.this.isFoot = Boolean.valueOf(true);
          AllAppForChildActivity.this.loadingData(false);
        }
      }
    });
    this.lvList.setOnLoadMoreListener(new PageListView.OnRefreshListener()
    {
      public void onRefresh()
      {
        AllAppForChildActivity.this.lvList.prepareForRefreshMore();
        AllAppForChildActivity.this.isFoot = Boolean.valueOf(true);
        AllAppForChildActivity.this.loadingData(true);
      }
    });
    addOperation(new DataTask().execute(new String[] { "installindex" }));
  }

  private void loadingData(boolean paramBoolean)
  {
    if (paramBoolean)
      this.page.firstPage();
    while (true)
    {
      addOperation(new DataTask().execute(new String[] { "installindex" }));
      return;
      this.page.nextPage();
    }
  }

  private void removeEvent(String paramString)
  {
    if ((eventsDown != null) && (eventsDown.size() > 0));
    for (int i = 0; ; i++)
    {
      if (i >= eventsDown.size())
        return;
      if (paramString.equals(((AutoSoftInfo)eventsDown.get(i)).getKeyID()))
      {
        eventsDown.remove(eventsDown.get(i));
        downAT.remove(paramString);
        return;
      }
    }
  }

  private void setCurrentProgressBar(String paramString, ProgressBar paramProgressBar, Button paramButton)
  {
    if (eventsDown.size() > 0)
      for (int i = 0; ; i++)
      {
        if (i >= eventsDown.size());
        do
        {
          return;
          if (!paramString.equals(((AutoSoftInfo)eventsDown.get(i)).getKeyID()))
            break;
          paramProgressBar.setVisibility(0);
          paramButton.setText("取消");
        }
        while (paramProgressBar.getMax() >= ((AutoSoftInfo)eventsDown.get(i)).getMaxLVState());
        paramProgressBar.setMax(((AutoSoftInfo)eventsDown.get(i)).getMaxLVState());
        logInfo("pbjindunew:" + paramProgressBar.toString());
        ((DownloadAsyncTask)downAT.get(paramString)).setProgressBar(paramProgressBar);
        return;
        paramProgressBar.setVisibility(8);
      }
    paramProgressBar.setProgress(0);
    paramProgressBar.setVisibility(8);
  }

  private void setEventIsCancelDown(Boolean paramBoolean, String paramString)
  {
    for (int i = 0; ; i++)
    {
      if (i >= eventsDown.size())
        return;
      if (paramString.equals(((AutoSoftInfo)eventsDown.get(i)).getKeyID()))
      {
        ((AutoSoftInfo)eventsDown.get(i)).setIsCancelDownload(paramBoolean);
        return;
      }
    }
  }

  private void setEventLVState(int paramInt1, String paramString, int paramInt2)
  {
    if ((eventsDown != null) && (eventsDown.size() > 0));
    for (int i = 0; ; i++)
    {
      if (i >= eventsDown.size());
      do
      {
        return;
        if (!paramString.equals(((AutoSoftInfo)eventsDown.get(i)).getKeyID()))
          break;
        ((AutoSoftInfo)eventsDown.get(i)).setLVState(paramInt1);
      }
      while (((AutoSoftInfo)eventsDown.get(i)).getMaxLVState() != 0);
      ((AutoSoftInfo)eventsDown.get(i)).setMaxLVState(paramInt2);
      return;
    }
  }

  private void showView(ProgressBar paramProgressBar, Button paramButton)
  {
    DownloadAsyncTask localDownloadAsyncTask = new DownloadAsyncTask();
    downAT.put(paramButton.getTag().toString(), localDownloadAsyncTask);
    localDownloadAsyncTask.execute(new View[] { paramProgressBar, paramButton });
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903147);
    isCancel = Boolean.valueOf(false);
    paused = Boolean.valueOf(false);
    initView();
  }

  protected void onResume()
  {
    super.onResume();
    this.adapter.notifyDataSetChanged();
  }

  class DataTask extends AsyncTask<String, Integer, String>
  {
    String param;

    DataTask()
    {
    }

    protected String doInBackground(String[] paramArrayOfString)
    {
      this.param = paramArrayOfString[0];
      if (this.param.equals("installindex"))
        AllAppForChildActivity.this.events = new RecomSoftServer(AllAppForChildActivity.this).installSoftWare(0, "", AllAppForChildActivity.this.etSearch.getText().toString(), 0, 0, AllAppForChildActivity.this.page.getPageNo(), AllAppForChildActivity.this.page.getPageSize());
      while (!this.param.equals("softRecd"))
        return null;
      HashMap localHashMap = new HashMap();
      localHashMap.put(AllAppForChildActivity.this.softid, Integer.valueOf(1));
      RqSP localRqSP = new RqSP();
      String str1 = localRqSP.getLgDevAccount(AllAppForChildActivity.this);
      String str2 = localRqSP.getLgDevId(AllAppForChildActivity.this);
      AllAppForChildActivity.this.bean = new RecomSoftServer(AllAppForChildActivity.this).updateRecd(localHashMap, str1, str2);
      return AllAppForChildActivity.this.bean.getDesc();
    }

    protected void onPostExecute(String paramString)
    {
      if (this.param.equals("installindex"))
        if ((AllAppForChildActivity.this.events != null) && (AllAppForChildActivity.this.events.size() > 0))
        {
          AllAppForChildActivity.this.page.addAllEntries(AllAppForChildActivity.this.events);
          AllAppForChildActivity.this.adapter.notifyDataSetChanged();
          AllAppForChildActivity.this.lvList.onLoadMoreComplete();
          if (AllAppForChildActivity.this.events.size() < AllAppForChildActivity.this.page.getPageSize())
          {
            AllAppForChildActivity.this.lvList.hideFotterMoreView();
            AllAppForChildActivity.this.lvList.setIsNoMore(true);
          }
          AllAppForChildActivity.this.events.clear();
          AllAppForChildActivity.this.blDataTask = true;
        }
      while (true)
      {
        if (!AllAppForChildActivity.this.isFoot.booleanValue())
        {
          AllAppForChildActivity.this.closeProgress();
          AllAppForChildActivity.this.isFoot = Boolean.valueOf(false);
        }
        super.onPostExecute(paramString);
        return;
        AllAppForChildActivity.this.lvList.hideFotterMoreView();
        AllAppForChildActivity.this.lvList.setIsNoMore(true);
        break;
        if (this.param.equals("softRecd"))
          if (AllAppForChildActivity.this.bean.getCode().equals("0"))
          {
            int i = AllAppForChildActivity.this.btnCurrent.getPaddingLeft();
            int j = AllAppForChildActivity.this.btnCurrent.getPaddingTop();
            int k = AllAppForChildActivity.this.btnCurrent.getPaddingRight();
            int m = AllAppForChildActivity.this.btnCurrent.getPaddingBottom();
            AllAppForChildActivity.this.btnCurrent.setText(AllAppForChildActivity.this.getResources().getString(2131427499));
            AllAppForChildActivity.this.btnCurrent.setTextColor(AllAppForChildActivity.this.getResources().getColor(2131230724));
            AllAppForChildActivity.this.btnCurrent.setBackgroundDrawable(AllAppForChildActivity.this.getResources().getDrawable(2130837636));
            AllAppForChildActivity.this.btnCurrent.setPadding(i, j, k, m);
            AllAppForChildActivity.this.alertMessage(AllAppForChildActivity.this.getResources().getString(2131427527));
          }
          else
          {
            AllAppForChildActivity.this.alertMessage(AllAppForChildActivity.this.getResources().getString(2131427528));
          }
      }
    }

    protected void onPreExecute()
    {
      AllAppForChildActivity.this.blDataTask = false;
      if (!AllAppForChildActivity.this.isFoot.booleanValue())
        AllAppForChildActivity.this.showProgress("");
      super.onPreExecute();
    }
  }

  class DownloadAsyncTask extends AsyncTask<View, Integer, Integer>
  {
    private Button btCurrent;
    private int fileSize;
    private String filename;
    private FileOutputStream fos;
    private InputStream is;
    private Boolean isCancelDownload = Boolean.valueOf(false);
    private String keyid;
    private ProgressBar pbCurrent;

    DownloadAsyncTask()
    {
    }

    protected Integer doInBackground(View[] paramArrayOfView)
    {
      this.pbCurrent = ((ProgressBar)paramArrayOfView[0]);
      this.btCurrent = ((Button)paramArrayOfView[1]);
      this.keyid = this.btCurrent.getTag().toString();
      this.filename = AllAppForChildActivity.this.apkpath.substring(1 + AllAppForChildActivity.this.apkpath.lastIndexOf("/"));
      try
      {
        URL localURL = new URL(AllAppForChildActivity.this.apkpath);
        Logger.e("xjf", "downpath: " + Global.SOFTPATHSDCARD);
        URLConnection localURLConnection = localURL.openConnection();
        localURLConnection.connect();
        this.is = localURLConnection.getInputStream();
        this.fileSize = localURLConnection.getContentLength();
        this.pbCurrent.setMax(this.fileSize);
        if (this.fileSize <= 0)
          throw new RuntimeException(AllAppForChildActivity.this.getString(2131427562));
      }
      catch (Exception localException)
      {
        this.fileSize = -1;
        localException.printStackTrace();
        Logger.d("xjf", localException.getMessage());
        return Integer.valueOf(this.fileSize);
        if (this.is == null)
          throw new RuntimeException("stream is null");
      }
      finally
      {
        this.isCancelDownload = Boolean.valueOf(false);
        com.appwoo.txtws.service.WebTimeControlService.isWho = Integer.valueOf(1);
      }
      label297: byte[] arrayOfByte;
      int i;
      if (Global.isSDCard())
      {
        this.fos = new FileOutputStream(Global.SOFTPATHSDCARD + this.filename);
        arrayOfByte = new byte[1024];
        i = 0;
        AllAppForChildActivity.this.logDebug("xjf fileSize:" + this.fileSize);
      }
      while (true)
      {
        boolean bool = this.isCancelDownload.booleanValue();
        if (bool);
        label524: int j;
        do
        {
          while (true)
          {
            this.isCancelDownload = Boolean.valueOf(false);
            com.appwoo.txtws.service.WebTimeControlService.isWho = Integer.valueOf(1);
            break;
            this.fos = AllAppForChildActivity.this.openFileOutput(this.filename, 1);
            break label297;
            do
            {
              AllAppForChildActivity.this.logDebug("zhy paused:" + AllAppForChildActivity.paused.toString());
              Thread.sleep(500L);
            }
            while (AllAppForChildActivity.paused.booleanValue());
            AllAppForChildActivity.this.logDebug("zhy paused:" + AllAppForChildActivity.paused.toString());
            this.isCancelDownload = AllAppForChildActivity.this.getIsCancelDown(this.keyid);
            if ((!this.isCancelDownload.booleanValue()) && (!AllAppForChildActivity.isCancel.booleanValue()))
              break label524;
            AllAppForChildActivity.this.logDebug("zhy download Cancel: " + this.filename);
            this.fileSize = -2;
          }
          com.appwoo.txtws.service.WebTimeControlService.isWho = Integer.valueOf(0);
          j = this.is.read(arrayOfByte);
        }
        while (j == -1);
        this.fos.write(arrayOfByte, 0, j);
        i += j;
        Integer[] arrayOfInteger = new Integer[1];
        arrayOfInteger[0] = Integer.valueOf(i);
        publishProgress(arrayOfInteger);
      }
    }

    public String getKeyID()
    {
      return this.keyid;
    }

    protected void onPostExecute(Integer paramInteger)
    {
      if (AllAppForChildActivity.isCancel.booleanValue())
        return;
      this.pbCurrent.setProgress(0);
      this.pbCurrent.setVisibility(8);
      AllAppForChildActivity.this.removeEvent(this.keyid);
      this.btCurrent.setEnabled(true);
      while (true)
      {
        try
        {
          Boolean localBoolean = Boolean.valueOf(Global.isSDCard());
          if (paramInteger.intValue() < 0)
            break label203;
          if (localBoolean.booleanValue())
          {
            if (paramInteger.intValue() != -1)
              Global.installApk(AllAppForChildActivity.this, Global.SOFTPATHSDCARD + this.filename);
            if (this.is != null)
              this.is.close();
            if (this.fos == null)
              break;
            this.fos.close();
            return;
          }
        }
        catch (Exception localException)
        {
          Logger.e("xjf", "error: " + localException.getMessage(), localException);
          return;
        }
        if (paramInteger.intValue() != -1)
        {
          Global.installApk(AllAppForChildActivity.this, Global.SOFTPATHMEMORY + this.filename);
          continue;
          label203: if (paramInteger.intValue() == -1)
            AllAppForChildActivity.this.alertMessage(AllAppForChildActivity.this.getString(2131428051));
        }
      }
    }

    protected void onPreExecute()
    {
    }

    protected void onProgressUpdate(Integer[] paramArrayOfInteger)
    {
      if (AllAppForChildActivity.isCancel.booleanValue())
        return;
      this.pbCurrent.setProgress(paramArrayOfInteger[0].intValue());
      AllAppForChildActivity.this.setEventLVState(paramArrayOfInteger[0].intValue(), this.keyid, this.pbCurrent.getMax());
      ((int)(100.0F * (this.pbCurrent.getProgress() / this.pbCurrent.getMax())));
    }

    public void setProgressBar(ProgressBar paramProgressBar)
    {
      this.pbCurrent = paramProgressBar;
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.activity.AllAppForChildActivity
 * JD-Core Version:    0.6.2
 */